local ClientOHOH = _G.ClientOHOH;

local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHOLYBUIBase());


function InitInsts(ui)
	ui.insts = {};
	ui.insts.CellPerfab ="ctrl.cell"
	ui.insts.luckValue ="ctrl.lucky"
	ui.insts.save ="ctrl.btn"	
end


function M.new(...)
	return M(...);
end;
function M.ctor(self)
	InitInsts(self)

	M.super.ctor(self, ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.WeaponDropInfoGui"));
	self.insts.CellPerfab.Visible=false
	self.CellList={}
end;


function M.dtor(self)
	M.super.dtor(self);
end;

function M.OnShow(self,data,luck)
	self:Clear()
    self:FullText(self.insts.luckValue,{luck})
	self:CreateCell(data)
end


function M.Clear(self)
	for _,v in pairs(self.CellList) do
		v:Destroy()
	end
	self.CellList={}
end


function M.CreateCell(self,data)
	 for k,v in pairs(data) do
		local cell=self.insts.CellPerfab:Clone()

		cell.Visible=true
		cell.Parent=self.insts.CellPerfab.Parent
		local ui=self:InitUiInst2(cell,{
			btn="ctrl.deleteBtn",
			deleteIcon="ctrl.deleteIcon",
			weight="ctrl.weight",
			weaponIcon="ctrl.weaponIcon",
		})

		if v.isDelete then
			ui.deleteIcon.Visible=true
		else
			ui.deleteIcon.Visible=false
		end

		ClientOHOH.load.CallBackManager():AddRbxConnect(self,ui.btn.Activated, function()
				ui.deleteIcon.Visible=not ui.deleteIcon.Visible
				v.DeleteEvent:Action(v)
				-- for _,p in pairs(list) do
				-- 	if p then
				-- 		ui.deleteIcon.Visible=not ui.deleteIcon.Visible
				-- 	end
				-- end
		end);

		ui.weight.Text=math.floor((v.weight)).."%"
		ui.weaponIcon.Image=v.icon

        self.CellList[v.id]=cell

	 end
end


return M